#include "head.h"
#include "mysql.h"

//复制时加上getprameter
int connMySQL(MYSQL* mysql)
{
    if( !mysql_real_connect(mysql,"localhost","root","123456","test2",0,NULL,0))
    {
        printf("%s\n",mysql_error(mysql));
        return 1;
    }
    return 0;
}
int functo(MYSQL* mysql,int net_fd)
{
    MYSQL_RES* result;
    MYSQL_ROW row;
    if(mysql_query(mysql,"select * from City"))
    {
        printf("%s\n",mysql_error(mysql));
        return 1;
    }

    result = mysql_store_result(mysql);
    row = mysql_fetch_row(result);
    int num = mysql_num_fields(result);
    char buff[1024] = {0};
    for(int i = 0; i < num;i++)
    {
        strcat(buff,row[i]);
        strcat(buff,"\t");
    }
   // printf("%s \n",buff);
    send(net_fd,buff,sizeof(buff),0);
    mysql_free_result(result); 
    return 0;
}
